<%@tag description="Contains the top level of a region-based overlay" pageEncoding="UTF-8"%>
<%-- Thanks to Jason Birch, http://www.jasonbirch.com/nodes/2006/06/13/21/wms-on-steroids-kml-21-regions-application/ --%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@attribute name="capabilities" required="true" type="uk.ac.rdg.resc.wms2kml.WMSCapabilities" description="Capabilities object"%>
<%@attribute name="layer" required="true" type="uk.ac.rdg.resc.wms2kml.Layer" description="Layer object"%>
<%@attribute name="baseURL" required="true" description="URL to use as a base for any callbacks to this server, e.g. in NetworkLinks"%>
<%@attribute name="elevation" required="false" description="Elevation value"%>
<%@attribute name="time" required="false" description="Time value"%>
<c:set var="href" value="${capabilities.getMapUrl}VERSION=${capabilities.version}&amp;REQUEST=GetMap&amp;LAYERS=${layer.name}&amp;STYLES=&amp;${capabilities.latLonProjectionCode}&amp;WIDTH=256&amp;HEIGHT=256&amp;FORMAT=${capabilities.compatibleImageFormat}&amp;TRANSPARENT=TRUE"/>
<c:set var="name" value="${layer.title}"/>
<c:set var="useDescription" value="true"/>
<c:if test="${not empty elevation}">
    <c:set var="name" value="${elevation} ${layer.elevationUnits}"/>
    <c:set var="useDescription" value="false"/>
    <c:set var="href" value="${href}&amp;ELEVATION=${elevation}"/>
</c:if>
<c:if test="${not empty time}">
    <c:set var="name" value="${time}"/>
    <c:set var="useDescription" value="false"/>
    <c:set var="href" value="${href}&amp;TIME=${time}"/>
</c:if>
<Folder>
    <name>${name}</name>
    <c:if test="${useDescription}">
        <description>${layer.description}</description>
    </c:if>
    <NetworkLink>
        <visibility>1</visibility> 
        <Region>
            <LatLonAltBox>
                <north>${layer.bbox.northLat}</north>
                <south>${layer.bbox.southLat}</south>
                <east>${layer.bbox.eastLon}</east>
                <west>${layer.bbox.westLon}</west>
            </LatLonAltBox>
            <Lod>
                <minLodPixels>380</minLodPixels> 
                <maxLodPixels>-1</maxLodPixels> 
            </Lod>
        </Region>
        <Link>
            <viewRefreshMode>onRegion</viewRefreshMode>
            <%-- Importing ${href} seems to automatically escape ampersands etc --%>
            <href>${baseURL}/createSubRegion?URL=${href}&amp;DBOX=${layer.bbox.westLon},${layer.bbox.southLat},${layer.bbox.eastLon},${layer.bbox.northLat}</href> 
        </Link>
        <c:if test="${not empty time}">
            <TimeStamp>
                <when>${time}</when>
            </TimeStamp>
        </c:if>
    </NetworkLink>
</Folder>
